import axios from "axios";
import {to} from "wsp-toolkit";
import {message} from "ant-design-vue";

export async function request({
                                  method = 'post',
                                  data,
                                  url,
                                  params,
                              }) {
    const headers = {};
    const token = localStorage.getItem('token');
    console.log('=token', token)
    if (token) {
        headers.token = token;
    }
    console.log('headers', headers)
    const result = axios.request({
        url,
        baseURL: 'http://localhost:8080',
        method,
        data,
        params,
        headers,
    })
    const [err, res] = await to(result);
    console.log('err', err);
    console.log('res', res);
    if (err) {
        message.error(err.message)
        throw new Error(res);
    }
    // TODO 返回处理
    return res?.data?.data;
}